﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;


namespace WindowsFormsAppOpenFile
{
    class Config
    {
        public void InitDomainConfig()
        {
            // 指定配置文件的路径
            string configFilePath = GValues.configPath; //"E:\\Program Files\\Autodesk\\AutoCAD 2014\\erptestdll\\config.txt";
            try
            {
                // 读取文本文件的所有行
                string[] lines = File.ReadAllLines(configFilePath);

                // 遍历每一行并处理配置信息
                foreach (string line in lines)
                {
                    // 假设配置文件的每一行都是以"键=值"的格式存储
                    string[] keyValue = line.Split('=');
                    if (keyValue.Length == 2)
                    {
                        string key = keyValue[0].Trim();
                        string value = keyValue[1].Trim();
                        // 在这里处理配置信息，例如存储到字典或使用
                        if (key == "domain")
                        {
                            GValues.domain = value;
                        }
                        try
                        {
                            if (key == "domainLink")
                            {
                                GValues.domainLink = value;
                            }
                            if (key == "searchPath")
                            {
                                GValues.searchPath = value;
                            }
                            if (key == "printName")
                            {
                                GValues.printName = value;
                            }
                            if (key == "remotePrint")
                            {
                                GValues.remotePrint = Convert.ToBoolean(value);
                            }
                            if (key == "CADDrawingPdf")
                            {
                                GValues.CADDrawingPdf = Convert.ToBoolean(value);
                            }
                            if (key == "CADProcessBom")
                            {
                                GValues.CADProcessBom = Convert.ToBoolean(value);
                            }
                            if (key == "ExcelProductBom")
                            {
                                GValues.ExcelProductBom = Convert.ToBoolean(value);
                            }
                            if (key == "companyName")
                            {
                                GValues.companyName = value;
                            }
                            if (key == "AcadPath")
                            {
                                GValues.AcadPath = value;
                            }
                            if (key == "Paper_SizeLength")
                            {
                                GValues.Paper_SizeLength = Convert.ToInt16(value);
                            }
                            if (key == "Paper_SizeWidth")
                            {
                                GValues.Paper_SizeWidth = Convert.ToInt16(value);
                            }
                        }
                        catch (System.Exception e)
                        {
                            //MessageBox.Show(e.ToString());
                        }
                    }
                }
            }
            catch (IOException e)
            {
                //LogHelper.WriteLog("读取配置文件时发生错误: " + e.Message, null);
            }

        }
    }
}
